package com.xydtech.ecard.custgroup.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.custgroup.domain.EcardCustomerOrganizeVisit;
import com.xydtech.ecard.custgroup.service.IEcardCustomerOrganizeVisitService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * EcardCustomerOrganizeVisitController
 *
 * @author yuzhiguo
 * @date 2024-12-03 上午11:18
 */
@Controller
@RequestMapping("/ecard/customerGroup/organize/visit")
public class EcardCustomerOrganizeVisitController extends BaseController
{
    private String prefix = "ecard/custgroup/organize";

    @Autowired
    private IEcardCustomerOrganizeVisitService ecardCustomerOrganizeVisitService;

//    @RequiresPermissions("organize:visit:view")
    @GetMapping("/{organizeId}")
    public String organizeVisit(@PathVariable("organizeId") String organizeId, ModelMap mmap)
    {
        mmap.put("organizeId", organizeId);
        return prefix + "/organizeVisit";
    }

    /**
     * 查询电子名片社团组织拜访记录列表
     */
//    @RequiresPermissions("organize:visit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardCustomerOrganizeVisit ecardCustomerOrganizeVisit)
    {
        startPage();
        List<EcardCustomerOrganizeVisit> list = ecardCustomerOrganizeVisitService.selectEcardCustomerOrganizeVisitList(ecardCustomerOrganizeVisit);
        return getDataTable(list);
    }

    /**
//     * 导出电子名片社团组织拜访记录列表
     */
    @RequiresPermissions("organize:visit:export")
    @Log(title = "电子名片社团组织拜访记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardCustomerOrganizeVisit ecardCustomerOrganizeVisit)
    {
        List<EcardCustomerOrganizeVisit> list = ecardCustomerOrganizeVisitService.selectEcardCustomerOrganizeVisitList(ecardCustomerOrganizeVisit);
        ExcelUtil<EcardCustomerOrganizeVisit> util = new ExcelUtil<EcardCustomerOrganizeVisit>(EcardCustomerOrganizeVisit.class);
        return util.exportExcel(list, "电子名片社团组织拜访记录数据");
    }

    /**
     * 新增电子名片社团组织拜访记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电子名片社团组织拜访记录
     */
//    @RequiresPermissions("organize:visit:add")
    @Log(title = "电子名片社团组织拜访记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardCustomerOrganizeVisit ecardCustomerOrganizeVisit)
    {
        return toAjax(ecardCustomerOrganizeVisitService.insertEcardCustomerOrganizeVisit(ecardCustomerOrganizeVisit));
    }

    /**
     * 修改电子名片社团组织拜访记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EcardCustomerOrganizeVisit ecardCustomerOrganizeVisit = ecardCustomerOrganizeVisitService.selectEcardCustomerOrganizeVisitById(id);
        mmap.put("ecardCustomerOrganizeVisit", ecardCustomerOrganizeVisit);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子名片社团组织拜访记录
     */
//    @RequiresPermissions("organize:visit:edit")
    @Log(title = "电子名片社团组织拜访记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardCustomerOrganizeVisit ecardCustomerOrganizeVisit)
    {
        return toAjax(ecardCustomerOrganizeVisitService.updateEcardCustomerOrganizeVisit(ecardCustomerOrganizeVisit));
    }

    /**
     * 删除电子名片社团组织拜访记录
     */
//    @RequiresPermissions("organize:visit:remove")
    @Log(title = "电子名片社团组织拜访记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ecardCustomerOrganizeVisitService.deleteEcardCustomerOrganizeVisitByIds(ids));
    }

    /**
     * 电子名片商户拜访状态修改
     * @param ecardCustomerOrganizeVisit
     * @return
     */
    @RequiresPermissions("organize:visit:edit")
    @Log(title = "电子名片社团组织拜访状态修改", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(EcardCustomerOrganizeVisit ecardCustomerOrganizeVisit) {
        return toAjax(ecardCustomerOrganizeVisitService.updateEcardCustomerOrganizeVisit(ecardCustomerOrganizeVisit));
    }
}
